// 主要用来封装D跳的时候的阴影
library DSkillData initializer init requires UnitUtil

    globals
        // 阴影单位
        unit array dShadowUnit

        // 阴影单位数量
        integer dShadowUnitNum = 10
    endglobals

    // 初始化
    private function initData takes nothing returns nothing

        // 初始创建好D跳的10个阴影
        // 用它的力量来记录透明度，默认100表示全透明
        local integer loopi 
        local integer uid

        set uid = 0
        loop
            exitwhen uid > PLAYER_NUMBER
            set loopi = 0
            loop
                exitwhen loopi >= dShadowUnitNum
                set dShadowUnit[uid * 20 + loopi] = CreateUnit(Player(uid), 'h002', 5156.0, -5488.0, 0.0)
                // 设置完全透明
                call SetUnitVertexColorBJ( dShadowUnit[uid * 20 + loopi], 0, 0, 0, 100.00 )
                // 设置动画暂停
                call SetUnitTimeScale( dShadowUnit[uid * 20 + loopi], 0.00 )
                set loopi = loopi + 1
            endloop
            
            set uid = uid + 1
        endloop

    endfunction

    // 选择完英雄后要初始化阴影的模型
    function initShadowMdl takes integer uid returns nothing
        local unit u = udg_player_select_hero[uid]
        local integer loopi
        local string mdl = getUnitModelString(u)
        set loopi = 0
        loop
            exitwhen loopi >= dShadowUnitNum
            call DzSetUnitModel( dShadowUnit[uid * 20 + loopi], mdl )
            set loopi = loopi + 1
        endloop

        set mdl = null
        set u = null
    endfunction

    // 设置透明度
    function setShadowUnitAlpha takes integer uid, integer i, real alpha returns nothing
        // 设置完全透明
        if dShadowUnit[uid * 20 + i] != null then
            call SetUnitVertexColorBJ( dShadowUnit[uid * 20 + i], 0, 0, 0, alpha )
        endif
    endfunction

    // 显示阴影
    function showShadowUnit takes integer uid, integer i, real x, real y, real angle returns nothing
        // 设为位置
        call SetUnitPosition( dShadowUnit[uid * 20 + i], x, y )
        // 设置面向角度
        call SetUnitFacing( dShadowUnit[uid * 20 + i], angle )
        // 设置透明度
        call setShadowUnitAlpha(uid, i, 36.0)
    endfunction

    // 隐藏阴影
    function hideShadowUnit takes integer uid, integer i returns nothing
        if dShadowUnit[uid * 20 + i] != null then
            // 隐藏单位
            call SetUnitPosition( dShadowUnit[uid * 20 + i], 13050.0, -19596.0 )
            // 设置完全透明
            call SetUnitVertexColorBJ( dShadowUnit[uid * 20 + i], 0, 0, 0, 100.00 )
        endif
    endfunction

    private function init takes nothing returns nothing
        call initData()
    endfunction
endlibrary


